#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include "Herb.h"
#include <QHash>
#include <QPushButton>
#include<QObject>

QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE

class Widget : public QWidget
{
    Q_OBJECT
    struct HerbSelection {
        Herb herb;
        QString role;  // "主药"/"辅药"/"药引"
        int position;  // 位置编号


    };


public:
    Widget(QWidget *parent = nullptr);
    ~Widget();


    struct EffectStats { // 新增结构体
        QHash<QString, int> main;
        QHash<QString, int> aid;
        bool isValid;
        EffectStats(QHash<QString, int> m, QHash<QString, int> a, bool v)
            : main(m), aid(a), isValid(v) {}
    };

    EffectStats checkeff(const QList<HerbSelection>& selections) const;

private slots:
    void onHerbButtonClicked(QPushButton* btn);
    void onStartAlchemy();


private:


    QHash<QString, QPair<QString, QString>> m_pillDatabase;
    void initPills();

    Ui::Widget *ui;

    QHash<QString,Herb> m_herbDatabase;

    void initHerbs();

    void setupButtons();
    void connectSlots();
    void updateButtonDisplay(QPushButton* btn, const QString& herbName);
    QList<HerbSelection> getCurrentSelections() const;
    bool checkThermalBalance(const QList<HerbSelection>& selections) const;

    QString parseRole(const QString& objectName) const;
    int parsePosition(const QString& objectName) const;

    void showSuccessPill();
    void clearPillDisplay();

};
#endif // WIDGET_H
